package LibDL.data;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;

import java.util.List;
import java.util.Random;

@BenchmarkMode(Mode.AverageTime)
@State(Scope.Thread)
public class LibArrayIntBM {

    private LibArrayInt test_argsort;

    @Param({"10000000"})
    private int length;

    @Setup
    public void setup() {
        Random r = new Random();
        int[] ints = new int[length];
        for (int i = 0; i < length; i++) {
            ints[i] = r.nextInt(200000);
        }
        test_argsort = new LibArrayInt(ints, length);
    }

//    @Benchmark
//    public List<Integer> argsort_boxed () {
//        return test_argsort.argsort_boxed();
//    }

    @Benchmark
    public LibArrayInt argsort() {
        return test_argsort.argsort();
    }

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(LibArrayInt.class.getSimpleName())
                .timeout(TimeValue.valueOf("30s"))
                .forks(1)
                .warmupIterations(5)
                .warmupTime(TimeValue.valueOf("3s"))
                .measurementIterations(4)
                .measurementTime(TimeValue.valueOf("10s"))
                .build();
        new Runner(options).run();
    }
}
